package com.itheima.conterller;

import com.itheima.config.SpringConfig;
import com.itheima.domain.Student;
import com.itheima.service.StudentService;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/studentServlet")
public class StudentConterller {
    @Autowired
    private  StudentService studentService;

    @GetMapping
    public List<Student> findAll() {
        return studentService.findAll();
    }

    @PostMapping
    public String save(@RequestBody Student student) {
        studentService.save(student);
        return "OK";
    }

    @GetMapping("/{id}")
    public Student findById(@PathVariable String id) {
        return studentService.findById(id);
    }

    @PutMapping
    public String update(@RequestBody Student student) {
        studentService.update(student);
        return "OK";
    }

    @DeleteMapping("/{id}")
    public String deleteById(@PathVariable String id) {
        studentService.deleteById(id);
        return "OK";
    }
}
